#!/usr/bin/env python
'''
Copyright (C) 2006, 2007 Aaron Spike, aaron@ekips.org

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'''

import os, sys
import pygame

path = os.path.dirname(os.path.abspath(sys.argv[0]))

def load_image(name, colorkey=None):
    fullname = os.path.join(path, 'data', name)
    try:
        image = pygame.image.load(fullname)
    except pygame.error, message:
        print 'Cannot load image:', name
        raise SystemExit, message
    image = image.convert_alpha()

    return image, image.get_rect()

def load_sound(name):
    class NoneSound:
        def play(self): pass
    if not pygame.mixer:
        return NoneSound()
    fullname = os.path.join(path, 'data', name)
    try:
        sound = pygame.mixer.Sound(fullname)
    except pygame.error, message:
        print 'Cannot load sound:', name
        raise SystemExit, message
    return sound

class Activity:
    def __init__(self, screen):        
        self.screen = screen
        
        self.background = pygame.Surface(self.screen.get_size())
        self.background = self.background.convert()
        self.setup_background()
        
        self.center = self.background.get_rect().center
        
        self.clock = pygame.time.Clock()
        self.quit = False
        self.changed = False
        self.mprev = None
        
    def setup_background(self):
        self.background.fill((0,0,0))
        
    def load_image(self, name, colorkey=None):
        return load_image(name, colorkey)
        
    def load_sound(self, name):
        return load_sound(name)
    
    def run(self):
        self.screen.blit(self.background, (0,0))
        self.setup()
        pygame.display.flip()
        while True:
            self.handle_events()
            if self.quit:
                break
            if self.changed:
                self.screen.blit(self.background, (0, 0))
                self.on_change()
                pygame.display.flip()
            self.changed = False
    
    def setup(self):
        pass 
        
    def handle_events(self):
        pass 
        
    def on_change(self):
        pass 
